package cn.message.service.impl;

import cn.itcast.mapper.imageMapper;
import cn.itcast.pojo.image;
import cn.itcast.pojo.imageExample;
import cn.message.service.ImageService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 郭智超
 * @create 2020-05-15 9:18
 * 图片管理的业务层实现类
 */
@Service
public class ImageServiceImpl implements ImageService {

    @Resource
    private imageMapper imageMapper;

    @Override
    public Map<String, Object> getAllImage(Map<String, String> map) {
        imageExample imageExample = new imageExample();

        //获取总记录数
        int count = imageMapper.countByExample(imageExample);

        int page = Integer.parseInt(map.get("page"));
        int limit = Integer.parseInt(map.get("limit"));
        //开始分页
        PageHelper.startPage(page,limit);
        List<image> imageList = imageMapper.selectByExample(imageExample);

        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("count",count);
        resultMap.put("imageList",imageList);
        return resultMap;
    }

    @Override
    public Boolean addImage(image image) {
        int i = imageMapper.insertSelective(image);
        if(i != 1){
            return false;
        }
        return true;
    }

    @Override
    public Boolean updateImage(image image) {
        int i = imageMapper.updateByPrimaryKeySelective(image);
        if(i != 1){
            return false;
        }
        return true;
    }

    @Override
    public Boolean deleteImage(Integer id) {
        int i = imageMapper.deleteByPrimaryKey(id);
        if(i != 1){
            return false;
        }
        return true;
    }

    @Override
    public image getImageById(Integer id) {

        return null;
    }
}
